const {Article} = require('../../model/article');
const pagenation = require('mongoose-sex-page');

module.exports = async (req,res) => {
    const page = req.query.page
    const count = await Article.countDocuments();
    const total = Math.ceil(count / 4);
    const result = await pagenation(Article).find().page(page).size(4).display(total).populate('author').exec();
    // const results = await Article.find();

    const result1 = JSON.stringify(result);
    const results = JSON.parse(result1);

    // res.send(results)
    // return;
    // console.log(results);

    res.render('home/index',{
        results: results,
    });
}